package com.overlook.somniferous.common.po;

import com.overlook.somniferous.common.Enum.CommonErrorEnum;
import com.overlook.somniferous.common.Enum.IResponseEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通用返回类型
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    private String code;

    private String message;

    private T data;

    public static <T> Result<T> success() {
        return new Result<T>(CommonErrorEnum.OK.getCode(), "", null);
    }

    public static <T> Result<T> successData(String code, String message, T data) {
        return new Result<>(code, message, data);
    }

    public static <T> Result<T> successData(String message, T data) {
        return new Result<>(CommonErrorEnum.OK.getCode(), message, data);
    }

    public static <T> Result<T> error(IResponseEnum responseEnum) {
        return new Result<>(responseEnum.getCode(), responseEnum.getMessage(), null);
    }

    public static <T> Result<T> error(String message,String code,T data){
        return new Result<>(message,code,data);
    }

    public static <T> Result<T> error(String message,String code){
        return new Result<>(code,message,null);
    }

}

